﻿@model Eqwww.Web.Areas.SystemManage.Models.Module.CreateViewModel
@using Eqwww.Domain.Models.SystemManage 

@{
    ViewData["Title"] = "新建模块";
    Layout = "~/Views/Shared/_ManageFormLayout.cshtml";
}


<form id="form1" class="mdui-m-t-3 mdui-m-b-3">
    <div asp-validation-summary="ModelOnly" class="mdui-textfield-error"></div>
    <div class="mdui-container">

        <div class="mdui-row">
            <div class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-textfield">
                    <label asp-for="ParentId" class="mdui-textfield-label"></label>
                    <input type="hidden" asp-for="ParentId" />
                    <input id="ParentName" name="ParentName" readonly="readonly" class="mdui-textfield-input mdui-color-grey-100" placeholder="==请选择==" />
                    <i class="mdui-icon material-icons" style="position:absolute;right:0;">arrow_drop_down</i>
                    <span asp-validation-for="ParentId" class="mdui-textfield-error"></span>
                </div>
            </div>
            <div class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-textfield">
                    <label asp-for="ModuleOpenType" class="mdui-textfield-label"></label>
                    <select asp-for="ModuleOpenType" class="mdui-textfield-input mdui-color-grey-100" asp-items="@Html.GetEnumSelectList(typeof(ModuleOpenType))">
                        <option value="">==请选择==</option>
                    </select>
                    <i class="mdui-icon material-icons" style="position:absolute;right:0;">arrow_drop_down</i>
                    <span asp-validation-for="ModuleOpenType" class="mdui-textfield-error"></span>
                </div>

            </div>
            <div class="mdui-col-xs-12 mdui-col-md-6">

                <div class="mdui-textfield mdui-textfield-floating-label">
                    <label asp-for="Code" class="mdui-textfield-label"></label>
                    <input asp-for="Code" class="mdui-textfield-input mdui-color-grey-100" />
                    <span asp-validation-for="Code" class="mdui-textfield-error"></span>
                </div>
            </div>
            <div class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-textfield mdui-textfield-floating-label">
                    <label asp-for="Name" class="mdui-textfield-label"></label>
                    <input asp-for="Name" class="mdui-textfield-input mdui-color-grey-100" />
                    <span asp-validation-for="Name" class="mdui-textfield-error"></span>
                </div>
            </div>

            <div class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-textfield">
                    <label asp-for="MenuMark" class="mdui-textfield-label"></label>
                    <select asp-for="MenuMark" class="mdui-textfield-input mdui-color-grey-100">
                        <option value="">==请选择==</option>
                        <option value="True">是</option>
                        <option value="False">否</option>
                    </select>
                    <i class="mdui-icon material-icons" style="position:absolute;right:0;">arrow_drop_down</i>
                    <span asp-validation-for="MenuMark" class="mdui-textfield-error"></span>
                </div>
            </div>
            <div class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-textfield mdui-textfield-floating-label">
                    <label asp-for="Url" class="mdui-textfield-label"></label>
                    <input asp-for="Url" class="mdui-textfield-input mdui-color-grey-100" />
                    <span asp-validation-for="Url" class="mdui-textfield-error"></span>
                </div>
            </div>
            <div class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-col-xs-10">
                    <div class="mdui-textfield mdui-textfield-floating-label">
                        <label asp-for="Icon" class="mdui-textfield-label"></label>
                        <input asp-for="Icon" value="arrow_forward" class="mdui-textfield-input mdui-color-grey-100" placeholder="图标参考Material Icons" />
                        
                        <span asp-validation-for="Icon" class="mdui-textfield-error"></span>
                    </div>
                </div>
                <div class="mdui-col-xs-2 mdui-m-t-4 mdui-text-right">
                    <a id="btnicon" href="javascript:;" class="mdui-btn mdui-btn-icon"><i class="mdui-icon material-icons mdui-float-right">arrow_forward</i></a>
                    
                </div>
                
            </div>
            <div class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-textfield mdui-textfield-floating-label">
                    <label asp-for="SortCode" class="mdui-textfield-label"></label>
                    <input asp-for="SortCode" value="0" class="mdui-textfield-input mdui-color-grey-100" />
                    <span asp-validation-for="SortCode" class="mdui-textfield-error"></span>
                </div>
            </div>

        </div>

    </div>
</form>


@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}

    <script>


        $(function () {
            /*
            var index = -1;

            $('#ParentName').click(function () {
                var $this = $(this);

                if (index < 0) {
                    index = layer.open({
                        id: 'TreeCollapse',
                        type: 2,
                        title: '<div class="mdui-m-l-2">请选择上级模块</div>',
                        content: '/SystemManage/Module/TreeCollapse',
                        shade: 0,
                        anim:0,
                        shadeClose:true,
                        area: [$this.outerWidth() + 'px', '400px'],
                        move: false,
                        fixed:false,
                        offset: [$this.offset().top + $this.outerHeight() + 'px', $this.offset().left + 'px'],
                        end: function () {
                            index = -1;
                        },
                        success: function (layero, index) {
                            var body = layer.getChildFrame('body', index);
                            var iframeWin = window[layero.find('iframe')[0]['name']];
                            iframeWin.$('.mdui-list-item-content').append('<a href="javascript:;" class="mdui-btn mdui-btn-dense eq-choose mdui-m-l-2 ">选择</a>');

                            iframeWin.$('.eq-choose').unbind().bind('click',function (e) {
                                e.preventDefault();
                                e.stopPropagation();
                                $('#ParentId').val($(this).parent().attr('data-id'));
                                $('#ParentName').val($(this).parent().attr('data-name'));
                                layer.close(index);
                                
                            });

                            $(window).resize(function () {
                                layero.css('top', $this.offset().top + $this.outerHeight() + 'px');
                                layero.css('left', $this.offset().left + 'px');
                                layero.css('width', $this.width()+'px');
                            });
                        }
                    });


                }
            });
            */


            $('#ParentName').SelectDown({
                url: '/SystemManage/Module/TreeCollapse',
                success: function (layero, index) {
                    var iframeWin = top.window[layero.find('iframe')[0]['name']];
                    iframeWin.$('.eq-choose').unbind().bind('click', function (e) {
                        e.preventDefault();
                        e.stopPropagation();
                        $('#ParentId').val($(this).parent().attr('data-id'));
                        $('#ParentName').val($(this).parent().attr('data-name'));
                        top.layer.close(index);

                    });
                }
            });

            $('#btnicon').SelectIcon({
                targetInput: '#Icon'
            });
        })

        function submitForm(){
            if (!$("#form1").valid()) {
                return false;
            }
            var postData = $('#form1').formSerialize();
            //alert(JSON.stringify(postData));
            $.submitForm({
                url: "/SystemManage/Module/Create",
                param: postData,
                success: function () {
                    $.currentWindow().location.reload();
                }
            });

        };
    </script>
}
